/**@FILE:OrderBackAction.java
 * @AUTHOR:qingsheng.zheng
 * @DATE:2015-2-1 上午11:40:29*/
package com.xf.toy.web;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.xf.pub.exception.ServiceException;
import com.xf.pub.logger.LoggerUtil;
import com.xf.toy.bean.OrderBack;
import com.xf.toy.dao.page.Pagination;
import com.xf.toy.service.OrderBackService;
import com.xf.toy.web.common.BaseAction;

/*******************************************
 * @COMPANY:alibaba
 * @CLASS:OrderBackAction
 * @DESCRIPTION:
 * @AUTHOR:qingsheng.zheng
 * @VERSION:v1.0
 * @DATE:2015-2-1 上午11:40:29
 *******************************************/
@Controller
@RequestMapping(value = "/toy/orderback")
public class OrderBackAction extends BaseAction {
	@Resource(name = "orderBackService")
	private OrderBackService orderBackService;
	private Long userid;

	@RequestMapping(value = "/create")
	public void orderBack(@RequestParam Long orderid,
			@RequestParam(required = false) Long expressid,
			@RequestParam(required = false) String rexcode,
			@RequestParam(required = false) String lostdesc,
			HttpServletRequest req, HttpServletResponse resp) {
		try {
			userid = super.getUserId(req);
			operLogger.info(LoggerUtil.logstr("method", "toy/orderback/create",
					"userid", userid + ""));
			orderBackService.orderback(orderid, rexcode, lostdesc);
			response(resp, null);
		} catch (ServiceException e) {
			response(resp, e);
		}
	}

	@RequestMapping(value = "/shelves")
	public void itemShelves(@RequestParam Long backid, HttpServletRequest req,
			HttpServletResponse resp) {
		try {
			userid = super.getUserId(req);
			operLogger.info(LoggerUtil.logstr("method",
					"toy/orderback/shelves", "userid", userid + ""));
			orderBackService.shelves(backid);
			response(resp, null);
		} catch (ServiceException e) {
			response(resp, e);
		}
	}

	@RequestMapping(value = "/backlist", method = RequestMethod.GET)
	public void backItemList(@RequestParam(required = false) String status,
			@RequestParam(required = false) String toycode,
			@RequestParam(required = false) Long userid,
			@RequestParam(required = false) Long backid,
			@RequestParam(required = false) Integer pageNo,
			@RequestParam(required = false) Integer pageSize,
			HttpServletRequest req, HttpServletResponse resp) {
		try {
			Pagination page = new Pagination();
			if (pageNo != null) {
				page.setPageSize(pageSize);
				page.setCurrentPage(pageNo);
			}
			Long myuserid = super.getUserId(req);
			OrderBack back = new OrderBack();
			back.setBackId(backid);
			back.setUserId(userid);
			back.setToyCode(toycode);
			operLogger.info(LoggerUtil.logstr("method",
					"toy/orderback/backlist", "userid", myuserid + ""));
			List<OrderBack> backs = orderBackService.selectListByStatus(back,
					status, page);
			response(resp, backs);
		} catch (ServiceException e) {
			response(resp, e);
		}
	}

}
